#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QDebug>
#include "Qt/workthread.h"
#include "Qt/socketclient.h"
#include "Qt/multithread.h"
#include "Qt/socketthread.h"
#include "Qt/obdii_4g.h"
#include "viewwindow.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void start_client(void);
    /*{
        qDebug() << "client start";
        workerThread = new ControllerThread();
        connect(workerThread->worker, &workThread::resultReady, this, &MainWindow::handleResults);
        //connect(workerThread, &Client::finished, workerThread, &QObject::deleteLater);
        workThread::start();
        workThread::mode(WORK_CLIENT);
        workerThread->start();
    }*/
    void start_download(void);
    void start_local_test(void)
    {
        qDebug() << "local start";
        workerThread = new ControllerThread();
        connect(workerThread->worker, &workThread::resultReady, this, &MainWindow::handleResults);
        //connect(workerThread, &Client::finished, workerThread, &QObject::deleteLater);
        workThread::start();
        workThread::mode(WORK_LOCAL);
        workerThread->start();
    }

public slots:
      void handleResults(const QString &str)
      {
          (void)str;
          //qDebug() << "client:" << str;
      }
//public slots:
    void handleThread(const QString result, const void* data);
//    void slotsClose(const QString obj)
//    {
//        if(0==obj.compare("ViewWindow"))
//        {
//            if(nullptr != viewer)
//            {
//                delete viewer;
//                viewer = nullptr;
//            }
//        }
//    }

private slots:
    void on_pushButton_clicked();

    void on_pushButton_work_clicked();

    void on_radioButton_info_clicked();

    void on_radioButton_RSA_clicked();

    void on_radioButton_SM2_clicked();

    void on_pushButton_download_clicked();

    void on_pushButton_cfg_clicked();

    void on_pushButton_list_clicked();

    void on_pushButton_test_clicked();

    void on_pushButton_Stop_clicked();

    void on_pushButton_Viewer_clicked();

    void on_pushButton_Multi_clicked();

    void on_pushButton_VIN_clicked();

    void on_pushButton_sql_clicked();

private:
    Ui::MainWindow *ui;
    ControllerThread *workerThread;
    enum ssl_type ssl;
    ViewWindow *viewer;
    SocketThread *ThreadClient;
    ControllerMultiThread *_controllerClient;
    SocketThread *ThreadDownload;
    ControllerMultiThread *_controllerDownload;
    SocketThread *thread_pond;
    ControllerMultiThread *_controller_pond;
};

#endif // MAINWINDOW_H
